<?php
add_mini_help('subdivisions');
require 'DB/db_data_loader.php';

/* Parameters */
switch (Addresing::get('load')) {
    case 'is':
        $load = 'is';
        break;
    default:
        $load = 'subdivision';
}
switch (Addresing::get('sort_by')) {
    case 'time':
        $sort_by = 'time';
        break;
    default:
        $sort_by = 'quantity';
}

$tab = Addresing::getRequestedTab();

/* Left menu */
if ($load == 'is')
    $class1 = 'class="current"';
else
    $class1 = '';
if ($load != 'is')
    $class2 = 'class="current"';
else
    $class2 = '';

MainDesign::leftSubmenuBeginning("Apkrova");
$sidebar_content .= '
<ul>
    <li><a ' . $class1 . ' href="?tab=' . $tab . '&amp;load=is&amp;sort_by=' . $sort_by . '">Informacinių sistemų</a></li>
    <li><a ' . $class2 . ' href="?tab=' . $tab . '&amp;load=subdivision&amp;sort_by=' . $sort_by . '">Padalinių</a></li>
</ul>';
MainDesign::leftSubmenuEnding();

if ($sort_by == 'time')
    $class1 = 'class="current"';
else
    $class1 = '';
if ($sort_by != 'time')
    $class2 = 'class="current"';
else
    $class2 = '';

MainDesign::leftSubmenuBeginning("Rušiuoti pagal");
$sidebar_content .= '
<ul>
    <li><a ' . $class1 . ' href="?tab=' . $tab . '&amp;load=' . $load . '&amp;sort_by=time">Sugaištą laiką</a></li>
    <li><a ' . $class2 . ' href="?tab=' . $tab . '&amp;load=' . $load . '&amp;sort_by=quantity">Suadministruotą kiekį</a></li>
</ul>';
MainDesign::leftSubmenuEnding();


MainDesign::leftSubmenuBeginning("Rodyti");
MainDesign::viewElementsList();
MainDesign::leftSubmenuEnding();


/* Content */
require 'Processing/Subdivisions/subdivision_data_processing.php';
$dataset = SubdivisionData::counts_to_dataset();
$subdivisions = get_subdivisios_associative();
$measures = get_support_measures_associative();
$dates = SubdivisionData::get_dates_predicted(12);
$time_groups = SubdivisionData::dataset_to_table($dataset, $subdivisions, $dates, $is_time_groups);
require 'LoadViewDesign.php';

/* Subdivisions */
if ($load == 'subdivision') {
    if (count($time_groups) > 0) {
        SubdivisionData::predict($time_groups);
        if ($sort_by == 'time') {
            MainDesign::h1('Padalinių apkrova pagal sugaištą laiką');
            MainDesign::viewSectionBegin('Taškinė apžvalgos diagrama');
                LoadViewDesign::dotted_sub($dates, $subdivisions, $time_groups, LoadViewDesign::DIAGRAM_MODE_TIME);
            MainDesign::viewSectionEnd();
            MainDesign::viewSectionBegin('Linijinė palyginamoji diagrama');
//                LoadViewDesign::linear_sub($dates, $subdivisions, $time_groups, LoadViewDesign::DIAGRAM_MODE_TIME);
                LoadViewDesign::linear_sub2($dates, $subdivisions, $time_groups, LoadViewDesign::DIAGRAM_MODE_TIME);
            MainDesign::viewSectionEnd();
            MainDesign::viewSectionBegin('Apkrovos lentelė');
                LoadViewDesign::table_sub($dates, $subdivisions, $time_groups, LoadViewDesign::TABLE_MODE_TIME);
            MainDesign::viewSectionEnd();
        } else {
            MainDesign::h1('Padalinių apkrova pagal paraiškų skaičių');
            
            /* Diagrams */
            MainDesign::viewSectionBegin('Taškinė apžvalgos diagrama');
                LoadViewDesign::dotted_sub($dates, $subdivisions, $time_groups, LoadViewDesign::DIAGRAM_MODE_ADMINISTRATED);
            MainDesign::viewSectionEnd();
            MainDesign::viewSectionBegin('Linijinė palyginamoji diagrama');
//                LoadViewDesign::linear_sub($dates, $subdivisions, $time_groups, LoadViewDesign::DIAGRAM_MODE_ADMINISTRATED);
                LoadViewDesign::linear_sub2($dates, $subdivisions, $time_groups, LoadViewDesign::DIAGRAM_MODE_TIME);
            MainDesign::viewSectionEnd();
            MainDesign::viewSectionBegin('Jungtinė apkrovos lentelė');
                LoadViewDesign::table_sub($dates, $subdivisions, $time_groups, LoadViewDesign::TABLE_MODE_QUANTYTI);
            MainDesign::viewSectionEnd();
        }
    } else {
        echo "Duomenų apie istorinius kiekius nėra. Pirma importuokite juos.";
    }

    /* Information system */
} else {
    require 'Processing/InformationSystems/is_data_processing.php';
    $is_names = get_is_associative();
    ISData::predict_is($is_time_groups);
    if ($sort_by == 'time') {
        MainDesign::h1('Informacinių sistemų apkrova pagal sugaištą laiką');
        
        MainDesign::viewSectionBegin('Taškinė apžvalgos diagrama');
            LoadViewDesign::dotted_is($dates, $is_names, $is_time_groups, LoadViewDesign::DIAGRAM_MODE_TIME);
        MainDesign::viewSectionEnd();
        MainDesign::viewSectionBegin('Taškinė apžvalgos diagrama');
            LoadViewDesign::linear_is($dates, $is_names, $is_time_groups, LoadViewDesign::DIAGRAM_MODE_TIME);
        MainDesign::viewSectionEnd();
        MainDesign::viewSectionBegin('Taškinė apžvalgos diagrama');
            LoadViewDesign::table_is($dates, $is_names, $is_time_groups, LoadViewDesign::TABLE_MODE_TIME);
        MainDesign::viewSectionEnd();
    } else {
        MainDesign::h1('Informacinių sistemų apkrova pagal paraiškų skaičių');
        
        MainDesign::viewSectionBegin('Taškinė apžvalgos diagrama');
            LoadViewDesign::dotted_is($dates, $is_names, $is_time_groups, LoadViewDesign::DIAGRAM_MODE_ADMINISTRATED);
        MainDesign::viewSectionEnd();
        MainDesign::viewSectionBegin('Taškinė apžvalgos diagrama');
            LoadViewDesign::linear_is($dates, $is_names, $is_time_groups, LoadViewDesign::DIAGRAM_MODE_ADMINISTRATED);
        MainDesign::viewSectionEnd();
        MainDesign::viewSectionBegin('Taškinė apžvalgos diagrama');
            LoadViewDesign::table_is($dates, $is_names, $is_time_groups, LoadViewDesign::TABLE_MODE_QUANTYTI);
        MainDesign::viewSectionEnd();
    }
}
?>
<br/>
Tamsesniame fone rodoma prognozuojama apkrova.<br/>
